<?php

	error_reporting(0);

	class Product {


		function Product(){
			
			include($_SERVER['DOCUMENT_ROOT'] . '/include/header.class.php');
			include($_SERVER['DOCUMENT_ROOT'] . '/include/parse.class.php');
			include($_SERVER['DOCUMENT_ROOT'] . '/include/menu.class.php'); 
			include($_SERVER['DOCUMENT_ROOT'] . '/include/db.class.php'); new Mysql;
		
		}

		function ShowProduct() {

			if(isset($_GET['p'])){

			if(strstr($_SERVER['REQUEST_URI'], '%20')){
				header( "HTTP/1.1 301 Moved Permanently" );
				header( "Location: http://www.myphpdigest.com".str_replace('%20','_',$_SERVER['REQUEST_URI']) );
			}

				$arr = Mysql::query('SELECT `Title`,`Article`,`Download`,`Example` FROM `products` WHERE `Title` = \''.str_replace('_',' ',$_GET['p']).'\'', TRUE);
				echo Header::CompileHeader($arr["Title"],substr($arr["Article"], 0, 200));
				Mysql::close();
				
				if($arr["Download"]==NULL){
					$d = 'No Download Availible';
					$style_d = 'file_n';
				} else {
					$d = '<a href="'.$arr["Download"].'">Download!</a>';
					$style_d = 'file_y';
				}
			
				if($arr["Example"]==NULL){
					$e = 'No Example Availible';
					$style_e = 'example_n';
				} else {
					$e = '<a href="'.$arr["Example"].'">View Example</a>';
					$style_e = 'example_y';
				}
				
				unset($GLOBALS['str']);
				echo Parser::Parse(array('template'=>'/template/product/main.tpl','bbcode'=>TRUE),
								array('{TITLE}','{DESC}','{STYLE_E}','{TEXT_E}','{STYLE_D}','{TEXT_D}'),
								array($arr["Title"],$arr["Article"],$style_e,$e,$style_d,$d));
								
				$quicklist = array($d,$e);
				echo Menu::CallFunctions($quicklist);

			} else {
				
				$rr = Mysql::query('SELECT `Title`,`Information`,`Download`,`Example` FROM `products` ORDER BY `PID` DESC', FALSE);$css=1;
				
				echo Header::CompileHeader('Products','Download FREE products provided by John\'s PHP Digest. PHP 100%, with great coding standards, examples and guides on how to operate eveything!');
				
				include($_SERVER['DOCUMENT_ROOT'] . '/template/product/header.tpl');
				
				$quicklist = array();
				unset($GLOBALS['str']);
				
				while($arr = Mysql::fetch_array($rr)) {
					if($css<2)$css=1;
					$link = str_replace(' ','_',$arr["Title"]);

					if($arr["Download"]==NULL){
						$style_d = 'file_n';$d_text = 'No Download Availible';
					} else {
						$style_d = 'file_y';$d_text = '<a href="'.$arr["Download"].'">Download!</a>';
					}
			
					if($arr["Example"]==NULL){
						$style_e = 'example_n';$e_text = 'No Example Availible';
					} else {
						$style_e = 'example_y';$e_text = '<a href="'.$arr["Example"].'">View Example</a>';
					}
					
					
					echo Parser::Parse(array('template'=>'/template/product/list.tpl','bbcode'=>FALSE),
								array('{TITLE}','{DESC}','{STYLE_E}','{TEXT_E}','{STYLE_D}','{TEXT_D}','{ID}','{URL}'),
								array($arr["Title"],$arr["Information"],$style_e,$e_text,$style_d,$d_text,$css,$link));

					$quicklist[] = '<a href="/product/'.$link.'">'.$arr["Title"].'</a>';
					$css++;
					
				} 

				Mysql::close();
				
				echo Menu::CallFunctions($quicklist,'product');
			}

		}

	}

?>